package com.starry.chat.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.switchMap
import com.starry.chat.logic.model.ChatBodyBean
import com.starry.chat.logic.network.Repository
import com.starry.core.viewmodel.BaseViewModel

/**
 * Package:com.starry.chat.viewmodel
 * Author:starr
 * Time:2024/4/6 16:05
 * Description: 聊天界面的ViewModel
 */
class ChatViewModel:BaseViewModel() {

    private val _tokenLiveData = MutableLiveData<String>()
    val token = _tokenLiveData.switchMap { _ ->
        Repository.getBaiduToken()
    }
    fun getBaiduToken() {
        _tokenLiveData.value = ""
    }

    private val _chatLiveData = MutableLiveData<Pair<ChatBodyBean,String>>()
    val chat = _chatLiveData.switchMap { (body,accessToken) ->
        Repository.startChat(body, accessToken)
    }
    fun startChat(body: ChatBodyBean,accessToken: String) {
        _chatLiveData.value = Pair(body,accessToken)
    }

}